package com.zjuee.web.basic.message.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.service.basic.message.service.MessageService;
import com.zjuee.service.basic.message.vo.NotificationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 短信 web 接口
 *
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping(path = Common.Service.ZJUEE_BASIC_MESSAGE_URL_PREFIX, name = Common.Service.ZJUEE_BASIC_SERVICE_NAME)
public class MessageController {

    @Resource
    private MessageService messageService;


    /**
     * 发送通知短信
     *
     * @param notificationVo NotificationVo
     * @return Boolean
     */
    @PostMapping("/phone/notification")
    public R<Boolean> sendNotification(@RequestBody NotificationVo notificationVo) {
        try {
            Boolean boo = messageService.sendNotification(notificationVo);
            if (null != boo) {
                return R.ok(boo);
            }
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.fail("Send Fail");
    }
}
